<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>任务列表</title>
    <script type="text/javascript" src="/script/mootools.js"></script>
    <script type="text/javascript" src="/script/mootools-more.js"></script>
    <link rel="stylesheet" type="text/css" href="/script/jspxnet-ui.css"/>
    <script type="text/javascript" src="/script/jspxnet.js"></script>
    <script type="text/javascript" src="/script/jspxnet-ui-roc.js"></script>
    <link rel="stylesheet" type="text/css" href="/script/jspxnet-ui.css"/>
    <link href="/share/mskin/default/devcenter.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript">
        var id = getUrlParam("id");
        window.addEvent('domready', function() {
            var columnModels = [
			    {"name":"guid","caption":"选择","type":"string","edit":true,"input":"selectbox","width":30},
				{"name":"started","caption":"当前状态","input":"selectShow","type":"number","option":[{"value":1,"name":"运行","ordinal":0},{"value":0,"name":"停止","ordinal":1}],"width":80,"edit":false},
				{"name":"guid","caption":"任务id","input":"text","type":"String","width":260,"edit":false},
				{"name":"name","caption":"服务名","input":"text","type":"String","width":200,"edit":false},
				{"name":"pattern","caption":"cron","input":"text","type":"String","width":100,"edit":false},
				{"name":"taskType","caption":"任务类型","input":"selectShow","type":"number","width":100,"option":[{"value":1,"name":"系统","ordinal":1},{"value":0,"name":"默认","ordinal":0}],"edit":false},
				{"name":"once","caption":"一次性","input":"selectShow","type":"number","width":80,"edit":false,"option":[{"value":1,"name":"是","ordinal":1},{"value":0,"name":"否","ordinal":0}]},
				{"name":"delayed","caption":"延时","input":"text","type":"String","width":50,"edit":false},
				{"name":"runTimes","caption":"运行次数","input":"text","type":"int","width":80,"edit":false},
				{"name":"methodName","caption":"方法名","input":"text","type":"String","width":80,"edit":false},
				{"name":"className","caption":"类名","input":"text","type":"String","width":300,"edit":false}
			];
            var buttons = [];
            buttons.push(new Element('button', {'type':'button','class':'jTDSelectAll','html':'全选',
                'events':
                    {
                        'click': function(event)
                        {
                            jtable.selectAll();
                            return false; //google 浏览器要
                        }
                    }
            }));
            buttons.push(new Element('button', {'type':'button','class':'jTDInverse','html':'返选',
                'events':
                    {
                        'click': function(event)
                        {
                            jtable.selectedConvert();
                            return false; //google 浏览器要
                        }
                    }
            }));
            buttons.push(new Element('div', {'class':'btnseparator'}));

            buttons.push(new Element('button', {'type':'button','class':'jTDUp','html':'运行',
                'events':
                    {
                        'click': function(event)
                        {

							 var selects = jtable.getSelecteds('guid');
                            //提示操作 begin
                            if(selects.length < 1) {
                                new JDialog.Alert({
                                    'message': '选择你要操作的行.'
                                }).show();
                                return false;
                            }
                            //提示操作 end
                            var posts = {'id':id,'guids':selects};							
	
							new Request.ROC({
								'url': '/devcenter/taskserv/start.jwc', data: posts,
								onSuccess: function (obj) {
                                    new JDialog.Pop({
                                            title: '消息提示',
                                            message:obj.message
                                    }).show();
									jtable.refresh();
								}
							}).post();

                            return false;
                        }
                    }
            }));
			//---------------------
			buttons.push(new Element('button', {'type':'button','class':'jTDTopRestore','html':'停止',
                'events':
                    {
                        'click': function(event)
                        {

							 var selects = jtable.getSelecteds('guid');
                            //提示操作 begin
                            if(selects.length < 1) {
                                new JDialog.Alert({
                                    'message': '选择你要操作的行.'
                                }).show();
                                return false;
                            }
                            //提示操作 end
                            var posts = {'id':id,'guids':selects};							
	
							new Request.ROC({
								'url': '/devcenter/taskserv/stop.jwc', data: posts,
								onSuccess: function (obj) {
                                    new JDialog.Pop({
                                            title: '消息提示',
                                            message:obj.message
                                    }).show();
									jtable.refresh();
								}
							}).post();

                            return false;
                        }
                    }
            }));
			//---------------------
			buttons.push(new Element('button', {'type':'button','class':'jTDAuditing','html':'运行1次',
                'events':
                    {
                        'click': function(event)
                        {

							 var selects = jtable.getSelecteds('guid');
                            //提示操作 begin
                            if(selects.length < 1) {
                                new JDialog.Alert({
                                    'message': '选择你要操作的行.'
                                }).show();
                                return false;
                            }
                            //提示操作 end
                            var posts = {'id':id,'guids':selects};							
	
							new Request.ROC({
								'url': '/devcenter/taskserv/forcerun.jwc', data: posts,
								onSuccess: function (obj) {
                                    new JDialog.Pop({
                                            title: '消息提示',
                                            message:obj.message
                                    }).show();
									jtable.refresh();
								}
							}).post();

                            return false;
                        }
                    }
            }));

			//---------------------
			buttons.push(new Element('button', {'type':'button','class':'jTDRefresh','html':'刷新',
                'events':
                    {
                        'click': function(event)
                        {
                            var posts = {'id':id};	
							new Request.ROC({
								'url': '/devcenter/taskserv/refresh.jwc', data: posts,
								onSuccess: function (obj) {
                                    new JDialog.Pop({
                                            title: '消息提示',
                                            message:obj.message
                                    }).show();
									jtable.refresh();
								}
							}).post();

                            return false;
                        }
                    }
            }));
           
            buttons.push(new Element('div', {'class':'btnseparator'}));
            var fen = new Element('label', {'html':'&nbsp;|&nbsp;','styles':{'float':'left','color':'#ffffff'}});
            buttons.push(fen);
            var findBox = new Element('input', {'type':'text','name':'find','id':'find'});
            var labelFind = new Element('label', {'html':'关键字','styles':{'float':'left'}});
            labelFind.adopt(findBox);
            buttons.push(labelFind);
            buttons.push(new Element('button', {'type':'button','class':'jTDRefresh','html':'搜索',
                'events':
                    {
                        'click': function(event)
                        {
							var postData = {
								'id':id,
								'find':findBox.get('value')
							}
							
                            jtable.loadData('/devcenter/taskserv/list/page.jwc',postData);
                            return false;
                        }
                    }
            }));
            jtable = new JDataTable({table:"grid",title:'任务列表',url:'/devcenter/taskserv/list/page.jwc',
                accordion:true,
                defaultParam:{'id':id},
                autoSectionToggle:false,
                showTog:true, //显示详细
                editMode:false,
                columnModels:columnModels,
                buttons:buttons,
                pagination:true,
                serverSort:true,
                showCaption: true,
                sortCaption: true,
                alternaterows: true,
                resizeColumns: true,
                multiselect:true,
				ondblclick:function (selects) {
                    var guid = selects.rowdata.guid;
					var pattern = selects.rowdata.pattern;
					
                   function display_prompt(_confirmed) {
						var varData = _confirmed.getElement('input').get('value');
						var posts = {'id':id,'guid':guid,'pattern':varData};
							new Request.ROC({
								'url': '/devcenter/taskserv/updatepattern.jwc', data: posts,
								onSuccess: function (obj) {
									if (obj.success) jtable.refresh();
                                    else {
                                        new JDialog.Alert({
                                            title: '消息提示',
                                            message:obj.message
                                        }).show();
                                    }
								}
						}).post();
				   }
				   new JDialog.Prompt({
						title: selects.rowdata.name,
						width:320,
						message: '定时表达式<input type="text" value="'+pattern+'">',
						callback: display_prompt
					}).show();

                }
            });
        });
    </script>
</head>
<body jskin="true">
<div class="mWrap">
    <div class="mTitPanel systemInfoLogo">任务列表</div>
    <div class="mConPanel">
        <div id="helpTip"></div>
        <div id="grid"></div>
    </div>
</div>
</body>
</html>
